#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int lcs(const string &s1, const string &s2, int i, int j, vector<vector<int>> &rec)
{
        if(rec[i][j] != -1){
                return rec[i][j];
        }
        if(i == s1.size() || j == s2.size()){
                return rec[i][j] = 0;
        }

        if(s1[i] == s2[j]){
                return rec[i][j] = lcs(s1, s2, i + 1, j + 1, rec) + 1;
        }else{
                return rec[i][j] = max(lcs(s1, s2, i + 1, j, rec), lcs(s1, s2, i, j + 1, rec));
        }
}

int main()
{
        string s1, s2;
        cin >> s1 >> s2;

        vector<vector<int>> rec(s1.size() + 1, vector<int>(s2.size() + 1, -1));

        cout<< lcs(s1, s2, 0, 0, rec) << endl;
        return 0;
}